Business Rule in Service-now

Business rules:

Its a configuration componant where we can write the script which will execute at server side.

What is Query?
1. Query refers to do some action on database. Query used for retriving data from Database.
2. To do any operation on DB we need to query in DB.
3. To do any operation on servicenow table, we need to query the DB.

We have following types of Business Rules:


A. Before Business rule:

Here we can run the script which will execute before the database operation.
In script, we can user current and previous object.
We should not use current.update() and current.insert() in before business rule.
      but in case we need to use, we need to use setWorkflow(false), so it will stop the other business rule.


1.Before Insert - Script will run before insert operation

2.Before Update - Script will run before update operation

3.Before Delete - Script will run before delete operation

4.Before Query - Script will run before Query operation


B. After Business Rule:

Here we can run the script which will execute after the database operation.
In script, we can use current and previous object.
This business rule run before the Async Business rule.

1.After Insert - Script will run after insert operation

2.After Update - Script will run after update operation

3.After Delete - Script will run after delete operation

4.After Query - Script will run after Query operation

C. Asyc Business Rule:

Here we can run the script which will execute after the database operation but independently.
This business rule will not hold the system to execute his script.
This business rule script will go in system schedule queue and will run according to system queue.
In script, we can use current object only but not previous object.
This business rule run after the After Business rule.

1.Asyc Insert - Script will run after insert operation asynchronously

2.Async Update - Script will run after update operation asynchronously

3.Async Delete - Script will run after delete operation asynchronously

4.Async Query - Script will run after query operation asynchronously

D. Display Business Rule:

Display - Script will run before displaying the data from server on the table form.
Using display rule we can encrypt the data (which is coming from database) before showing to customer on the form.
This will run after DB query and while displaying the data on the table form.
Display Business rule will run while displaying the data on the form, it will not work for list view.